/********************************************************/
/*	Author:		gong_libin			*/
/*	Date:		2014_08_14			*/
/*	File:		GtRmSend.c			*/
/********************************************************/

#include "GtGlobal.h"
#include <arpa/inet.h>
#include <unistd.h>

int main(int argc, char* argv[])
{
	int iLength = 0;
	int iSocket = 0;
	char* pszHost = NULL;
	char* pszPort = NULL;
	UCHAR* puszData = NULL;
	struct sockaddr_in stAddr;
	UCHAR uszRads[] = {
		0x04, 0xbf, 0x00, 0xb4, 0x35, 0x84, 0xd8, 0xea, 0x9f, 0x95, 0x31, 0xcd, 0x89, 0x1d, 0x2b, 0x49,
		0xd8, 0xea, 0xb5, 0xea, 0x2c, 0x1d, 0x37, 0x30, 0x30, 0x33, 0x33, 0x31, 0x30, 0x31, 0x35, 0x37,
		0x34, 0x32, 0x70, 0x70, 0x70, 0x31, 0x30, 0x30, 0x38, 0x36, 0x35, 0x39, 0x36, 0x65, 0x35, 0x34,
		0x39, 0x04, 0x06, 0x3c, 0x1e, 0xe0, 0x0e, 0x29, 0x06, 0x00, 0x00, 0x00, 0x00, 0x28, 0x06, 0x00,
		0x00, 0x00, 0x01, 0x20, 0x07, 0x5a, 0x58, 0x55, 0x41, 0x53, 0x01, 0x0c, 0x78, 0x30, 0x31, 0x31,
		0x39, 0x40, 0x61, 0x64, 0x73, 0x6c, 0x1f, 0x1c, 0x30, 0x34, 0x30, 0x35, 0x31, 0x37, 0x30, 0x30,
		0x39, 0x64, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x65, 0x30, 0x34, 0x64, 0x61, 0x33, 0x35, 0x63,
		0x61, 0x36, 0x08, 0x06, 0x3c, 0x1e, 0xec, 0xcd, 0x2d, 0x06, 0x00, 0x00, 0x00, 0x01, 0x05, 0x06,
		0x45, 0x17, 0x00, 0x9d, 0x3d, 0x06, 0x00, 0x00, 0x00, 0x0d, 0x57, 0x1e, 0x61, 0x74, 0x6d, 0x20,
		0x34, 0x2f, 0x30, 0x2f, 0x35, 0x3a, 0x32, 0x33, 0x2e, 0x31, 0x35, 0x37, 0x20, 0x30, 0x2f, 0x30,
		0x2f, 0x30, 0x2f, 0x30, 0x2f, 0x30, 0x2f, 0x30, 0x06, 0x06, 0x00, 0x00, 0x00, 0x02, 0x07, 0x06,
		0x00, 0x00, 0x00, 0x01,
	};
	UCHAR uszGtpc[] = {
		0x32, 0x10, 0x00, 0x8e, 0x00, 0x00, 0x00, 0x00, 0x06, 0x14, 0xff, 0x00, 0x02, 0x64, 0x00, 0x12,
		0x63, 0x44, 0x00, 0x68, 0xf2, 0x03, 0x64, 0xf0, 0x00, 0xff, 0xfe, 0xff, 0x0f, 0xfc, 0x10, 0x00,
		0x00, 0x02, 0xe0, 0x11, 0x09, 0x00, 0x00, 0x63, 0x14, 0x05, 0x80, 0x00, 0x02, 0xf1, 0x21, 0x83,
		0x00, 0x06, 0x05, 0x43, 0x4d, 0x4e, 0x45, 0x54, 0x84, 0x00, 0x14, 0x80, 0x80, 0x21, 0x10, 0x01,
		0x01, 0x00, 0x10, 0x81, 0x06, 0x00, 0x00, 0x00, 0x00, 0x83, 0x06, 0x00, 0x00, 0x00, 0x00, 0x85,
		0x00, 0x04, 0xdd, 0xb1, 0x9c, 0xa3, 0x85, 0x00, 0x04, 0xdd, 0xb1, 0x9c, 0xa3, 0x86, 0x00, 0x08,
		0x91, 0x68, 0x51, 0x31, 0x46, 0x04, 0x68, 0xf2, 0x87, 0x00, 0x0c, 0x02, 0x23, 0x92, 0x1f, 0x93,
		0x96, 0x40, 0x97, 0x74, 0x80, 0xff, 0xff, 0x97, 0x00, 0x01, 0x01, 0x98, 0x00, 0x08, 0x01, 0x64,
		0xf0, 0x00, 0xb7, 0x03, 0xe7, 0x5a, 0x99, 0x00, 0x02, 0x20, 0xfc, 0x9a, 0x00, 0x08, 0x68, 0x00,
		0x98, 0x00, 0x40, 0x70, 0x92, 0x99,
	};
	UCHAR uszGtpu[] = {
		0x30, 0xff, 0x00, 0xc5, 0x8a, 0x66, 0x63, 0x39, 0x45, 0x00, 0x00, 0xc5, 0x87, 0xc8, 0x40, 0x00,
		0x40, 0x06, 0x49, 0xcc, 0x0a, 0x4b, 0xb4, 0x37, 0xac, 0x13, 0xfe, 0x08, 0x99, 0xe8, 0x00, 0x50,
		0xf3, 0xda, 0x6e, 0xa7, 0xa2, 0xe5, 0x74, 0x1c, 0x50, 0x18, 0x0b, 0x18, 0x40, 0xdb, 0x00, 0x00,
		0x47, 0x45, 0x54, 0x20, 0x2f, 0x20, 0x48, 0x54, 0x54, 0x50, 0x2f, 0x31, 0x2e, 0x31, 0x0d, 0x0a,
		0x55, 0x73, 0x65, 0x72, 0x2d, 0x41, 0x67, 0x65, 0x6e, 0x74, 0x3a, 0x20, 0x44, 0x61, 0x6c, 0x76,
		0x69, 0x6b, 0x2f, 0x31, 0x2e, 0x34, 0x2e, 0x30, 0x20, 0x28, 0x4c, 0x69, 0x6e, 0x75, 0x78, 0x3b,
		0x20, 0x55, 0x3b, 0x20, 0x41, 0x6e, 0x64, 0x72, 0x6f, 0x69, 0x64, 0x20, 0x32, 0x2e, 0x33, 0x2e,
		0x34, 0x3b, 0x20, 0x47, 0x4e, 0x32, 0x30, 0x35, 0x20, 0x42, 0x75, 0x69, 0x6c, 0x64, 0x2f, 0x47,
		0x52, 0x4a, 0x32, 0x32, 0x29, 0x0d, 0x0a, 0x48, 0x6f, 0x73, 0x74, 0x3a, 0x20, 0x77, 0x77, 0x77,
		0x2e, 0x62, 0x61, 0x69, 0x64, 0x75, 0x2e, 0x63, 0x6f, 0x6d, 0x0d, 0x0a, 0x43, 0x6f, 0x6e, 0x6e,
		0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x3a, 0x20, 0x4b, 0x65, 0x65, 0x70, 0x2d, 0x41, 0x6c, 0x69,
		0x76, 0x65, 0x0d, 0x0a, 0x41, 0x63, 0x63, 0x65, 0x70, 0x74, 0x2d, 0x45, 0x6e, 0x63, 0x6f, 0x64,
		0x69, 0x6e, 0x67, 0x3a, 0x20, 0x67, 0x7a, 0x69, 0x70, 0x0d, 0x0a, 0x0d, 0x0a,
	};
	UCHAR uszFfRd[] = {
		0x78, 0x23, 0xa0, 0x74, 0x84, 0x00, 0x93, 0xff, 0x00, 0x01, 0x00, 0x01, 0x00, 0x16, 0x73, 0x47,
		0x73, 0x44, 0x47, 0x36, 0x51, 0x50, 0x53, 0x2f, 0x2f, 0x7a, 0x4a, 0x79, 0x2f, 0x52, 0x43, 0x69,
		0x68, 0x68, 0x64, 0x67,
	};
	UCHAR uszFfHp[] = {
		0x75, 0x1e, 0x80, 0xa2, 0x79, 0x09, 0xcf, 0x30, 0xce, 0x8d, 0x00, 0x50, 0x3a, 0xa7, 0xff, 0xf4,
		0x2c, 0x52, 0x5c, 0x66, 0x01, 0xa5, 0x01, 0x00, 0x00, 0x01, 0x00, 0x0c, 0x75, 0x32, 0x2e, 0x74,
		0x64, 0x69, 0x6d, 0x67, 0x2e, 0x63, 0x6f, 0x6d, 0x00, 0x02, 0x00, 0x36, 0x2f, 0x35, 0x2f, 0x32,
		0x35, 0x36, 0x2f, 0x38, 0x37, 0x2f, 0x5f, 0x31, 0x36, 0x39, 0x34, 0x37, 0x35, 0x30, 0x30, 0x33,
		0x33, 0x33, 0x32, 0x33, 0x35, 0x39, 0x37, 0x34, 0x33, 0x31, 0x31, 0x30, 0x32, 0x33, 0x30, 0x32,
		0x32, 0x30, 0x36, 0x33, 0x37, 0x31, 0x34, 0x33, 0x33, 0x38, 0x35, 0x38, 0x39, 0x35, 0x2e, 0x6a,
		0x70, 0x67, 0x00, 0x03, 0x00, 0x66, 0x68, 0x74, 0x74, 0x70, 0x3a, 0x2f, 0x2f, 0x77, 0x77, 0x77,
		0x2e, 0x74, 0x75, 0x64, 0x6f, 0x75, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x61, 0x6c, 0x62, 0x75, 0x6d,
		0x70, 0x6c, 0x61, 0x79, 0x2f, 0x38, 0x47, 0x55, 0x6f, 0x77, 0x75, 0x59, 0x64, 0x67, 0x57, 0x6b,
		0x2f, 0x39, 0x57, 0x79, 0x48, 0x79, 0x72, 0x56, 0x5f, 0x53, 0x6d, 0x6f, 0x2e, 0x68, 0x74, 0x6d,
		0x6c, 0x3f, 0x74, 0x70, 0x61, 0x3d, 0x64, 0x57, 0x35, 0x70, 0x62, 0x32, 0x35, 0x66, 0x61, 0x57,
		0x51, 0x39, 0x4d, 0x54, 0x41, 0x79, 0x4d, 0x6a, 0x45, 0x7a, 0x58, 0x7a, 0x45, 0x77, 0x4d, 0x44,
		0x41, 0x77, 0x4d, 0x56, 0x38, 0x77, 0x4d, 0x56, 0x38, 0x77, 0x4d, 0x51, 0x00, 0x04, 0x00, 0x3f,
		0x4d, 0x6f, 0x7a, 0x69, 0x6c, 0x6c, 0x61, 0x2f, 0x35, 0x2e, 0x30, 0x20, 0x28, 0x63, 0x6f, 0x6d,
		0x70, 0x61, 0x74, 0x69, 0x62, 0x6c, 0x65, 0x3b, 0x20, 0x4d, 0x53, 0x49, 0x45, 0x20, 0x39, 0x2e,
		0x30, 0x3b, 0x20, 0x57, 0x69, 0x6e, 0x64, 0x6f, 0x77, 0x73, 0x20, 0x4e, 0x54, 0x20, 0x36, 0x2e,
		0x31, 0x3b, 0x20, 0x54, 0x72, 0x69, 0x64, 0x65, 0x6e, 0x74, 0x2f, 0x35, 0x2e, 0x30, 0x29, 0x00,
		0x06, 0x00, 0x05, 0x7a, 0x68, 0x2d, 0x43, 0x4e,
	};

	if (argc < 3) {
		GT_PRINT("Usage: %s 192.168.0.10 1813\n", argv[0]);
		return GT_SUCCESS;
	}
	else {
		pszHost = argv[1];
		pszPort = argv[2];
	}

	switch (atoi(pszPort)) {
		case 1813:
			iLength = sizeof(uszRads);
			puszData = uszRads;
			break;
		case 2123:
			iLength = sizeof(uszGtpc);
			puszData = uszGtpc;
			break;
		case 2152:
			iLength = sizeof(uszGtpu);
			puszData = uszGtpu;
			break;
		case 11000:
			iLength = sizeof(uszFfRd);
			puszData = uszFfRd;
			break;
		case 11001:
			iLength = sizeof(uszFfHp);
			puszData = uszFfHp;
			break;
		default:
			break;
	}

	memset(&stAddr, '\0', sizeof(stAddr));
	if (GT_FAILURE != (iSocket = socket(AF_INET, SOCK_DGRAM, 0))) {
		stAddr.sin_family = AF_INET;
		stAddr.sin_port = htons(atoi(pszPort));
		stAddr.sin_addr.s_addr = inet_addr(pszHost);

		sendto(iSocket, puszData, iLength, 0, (struct sockaddr*)&stAddr, sizeof(struct sockaddr_in));

		close(iSocket);
	}

	return GT_SUCCESS;
}
